﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

namespace PM.PMSys
{
    /// <summary>
    /// 关于系统附件的操作
    /// </summary>
    public class attached
    {
        public attached()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }
        /// <summary>
        /// 插入日志
        /// </summary>
        /// <param name="filename">文件名称</param>
        /// <param name="filepath">文件相对路径</param>
        /// <param name="filetype">文件的类型</param>
        public void Insert_Attach(string filename, string filepath,string filetype)
        {
            try
            {
                SqlParameter[] AttSqlParameter ={ 
                new SqlParameter("@filename",SqlDbType.NVarChar),
                new SqlParameter("@filepath",SqlDbType.NVarChar),
                new SqlParameter("@filetype",SqlDbType.NVarChar)};
                AttSqlParameter[0].Value = filename;
                AttSqlParameter[1].Value = filepath;
                AttSqlParameter[2].Value = filetype;

                StringBuilder sqlstr = new StringBuilder("insert into Sys_Attached(");
                sqlstr.Append("filename,filepath,createdate,filetype,status)");
                sqlstr.Append(" values(");
                sqlstr.Append("@filename,@filepath,getdate(),@filetype,1)");
                PM.Code.DAL.DbHelper.ExecuteSql(sqlstr.ToString(), AttSqlParameter);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 附件（启用/禁用）
        /// </summary>
        /// <param name="id">附件编号</param>
        /// <param name="value">值</param>
        /// <returns>返回受影响的行数</returns>
        public int Update_AttachedStatus(int id, int value)
        {
            try
            {
                SqlParameter[] DictSqlParameter ={ 
                new SqlParameter("@id",SqlDbType.Int),
                new SqlParameter("@status",SqlDbType.TinyInt)};
                DictSqlParameter[0].Value = id;
                DictSqlParameter[1].Value = value;
                StringBuilder sqlstr = new StringBuilder("update Sys_Attached set status=@status where id=@id");
                return PM.Code.DAL.DbHelper.ExecuteSql(sqlstr.ToString(), DictSqlParameter);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 更新文件名称
        /// </summary>
        /// <param name="filename">文件名称</param>
        /// <param name="id">附件编号</param>
        /// <returns>返回受影响的行数</returns>
        public int Update_AttachedName(string filename,int id)
        {
            try
            {
                SqlParameter[] AttSqlParameter ={ 
                new SqlParameter("@id",SqlDbType.Int),
                new SqlParameter("@filename",SqlDbType.NVarChar)};
                AttSqlParameter[0].Value = id;
                AttSqlParameter[1].Value = filename;
                StringBuilder sqlstr = new StringBuilder("update Sys_Attached set filename=@filename where id=@id");
                return PM.Code.DAL.DbHelper.ExecuteSql(sqlstr.ToString(), AttSqlParameter);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
    }
}
